package com.hhu.wangzb.server.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hhu.wangzb.common.entity.filter.EntityFilter;
import com.hhu.wangzb.common.entity.PvComponentEntity;
import com.hhu.wangzb.server.service.PvComponentService;
import com.hhu.wangzb.common.utils.PageUtils;
import com.hhu.wangzb.common.utils.R;



/**
 * 
 *
 * @author wangzb
 * @email 494199942@qq.com
 * @date 2021-07-03 17:37:59
 */
@RestController
public class PvComponentController {

    @Autowired
    private PvComponentService pvComponentService;

    @Autowired
    private EntityFilter entityFilter;

    /**
     * 获取全部数据（分页数据，排序数据...）
     */
    @GetMapping("/pvComponents")
    public R list(@RequestParam Map<String, Object> params, String filter) {
        PageUtils page = pvComponentService.queryPage(params);

        page.setList((List<?>) entityFilter.filterList(page.getList(), filter));

        return R.ok().put("page", page);
    }


    /**
     * 获取某条数据
     */
    @GetMapping("/pvComponent/{id}")
    public R info(@PathVariable("id") Integer id, String filter) {
		PvComponentEntity pvComponent = pvComponentService.getById(id);

        Object o = entityFilter.filterEntity(pvComponent, filter);

        return R.ok().put("pvComponent", o);
    }

    /**
     * 创建
     */
    @PutMapping("/pvComponent")
    public R save(@RequestBody PvComponentEntity pvComponent){
		pvComponentService.save(pvComponent);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/pvComponent")
    public R update(@RequestBody PvComponentEntity pvComponent){
		pvComponentService.updateById(pvComponent);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/pvComponent")
    public R delete(Integer[] ids){
		pvComponentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
